package com.gosophia.conference.action.confPrepare;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.gosophia.commons.web.action.BaseSupportAction;
import com.gosophia.conferenceManagement.confPreparation.dto.ParticipatingNameListDTO;
import com.gosophia.conferenceManagement.confPreparation.ws.ConfPreparationWebService;
import com.gosophia.oa.action.JudgeCurrentUndertaker;
import com.opensymphony.xwork2.ActionContext;
/**
 * 更新参会名单列表
 * @author wangxinbing
 * @since  2011-3-26
 *  Copyright (c) 2010 Gosophia corporation All Rights Reserved
 */
@Component("UpdateParticipatingNameListAction")
@Scope("prototype")
public class UpdateParticipatingNameListAction extends BaseSupportAction {
	private static final long serialVersionUID = 1L;

	@Autowired
	private ConfPreparationWebService confPreparationWebService;
	@Autowired
	private JudgeCurrentUndertaker judgeCurrentUndertaker;
	private Long jobId;
	
	private List<ParticipatingNameListDTO> particiLists;
	
	private String resultMessage;
	@Override
	public String _execute() throws Exception {
		//判断是否匹配,如果不匹配转到异常页面
        judgeCurrentUndertaker.judgeOperationAuthority(jobId);
		//删除列表中用户名为空的列表项
		List<ParticipatingNameListDTO> deleteList = new ArrayList<ParticipatingNameListDTO>();
		if(particiLists !=null){
        	for(int i = 0; i<particiLists.size();i++){
				if (particiLists.get(i) == null
						|| particiLists.get(i).getUserName() == null
						|| particiLists.get(i).getUserName().trim().length()==0) {
					deleteList.add(particiLists.get(i));
				}
        	}
        	if(deleteList !=null && deleteList.size()!=0){
            	particiLists.removeAll(deleteList);
        	}
        }
		confPreparationWebService.updateParticipatingNameList(jobId, particiLists);
		super.getRequestResult().setMessage("保存成功！");
		super.getRequestResult().setRsltCode("0");
		ActionContext.getContext().getSession().put("_lastOpResult",
				super.getRequestResult());
		return SUCCESS;
	}
	public Long getJobId() {
		return jobId;
	}
	public void setJobId(Long jobId) {
		this.jobId = jobId;
	}
	public List<ParticipatingNameListDTO> getParticiLists() {
		return particiLists;
	}
	public void setParticiLists(List<ParticipatingNameListDTO> particiLists) {
		this.particiLists = particiLists;
	}
}
